package com.shinemo.mpush.alloc.http;

import com.mpush.netty.http.HttpCallback;
import io.netty.handler.codec.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DefaultHttpCallback implements HttpCallback {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private final String url;

    public DefaultHttpCallback(String url){
        this.url = url;
    }

    @Override
    public void onResponse(HttpResponse response) {
        if(logger.isInfoEnabled()){
            logger.info("{}",response);
        }
    }

    @Override
    public void onFailure(int statusCode, String reasonPhrase) {
        if(logger.isInfoEnabled()){
            logger.info("{}:{}",statusCode,reasonPhrase);
        }
    }

    @Override
    public void onException(Throwable throwable) {
        if(logger.isInfoEnabled()){
            logger.info("",throwable);
        }
    }

    @Override
    public void onTimeout() {
        if(logger.isInfoEnabled()){
            logger.info("{} time out",this.url);
        }
    }

    @Override
    public boolean onRedirect(HttpResponse response) {
        return false;
    }
}
